import BaseController from '../../core/controllers/Base.controller';

@Inject('$log', '$scope', '$rootScope', '$state', 'globalService', 'deviceService', 'ngDialogService')
class AddDeviceInfoController extends BaseController {
  constructor() {
    super();

    this.view = {
      avatarFile: null,
      attachmentFiles: [],
    };

    this.equipInfo = {};
  }

  $saveDeviceInfo(param) {
    this.equipInfo.operatorIds = [];
    this.equipInfo.operatorIds = this.selectedWorkers.map(item => item.id);
    this.equipInfo.attachmentIds = this.view.attachmentFiles.map(item => item.id);
    if (this.view.avatarFile && this.view.avatarFile.id) {
      this.equipInfo.imageId = this.view.avatarFile.id;
    }
    this.$log.info(param, this.equipInfo);
    this.deviceService
      .save(this.equipInfo)
      .then((res) => {
        this.$log.debug(res);
        if (res.success) {
          this.ngDialogService.alertSuccess(res.message);
          this.$state.go('deviceInfoDetail', { id: res.data.id });
        } else {
          this.ngDialogService.alertError(res.message);
        }
      });
  }


}

export default AddDeviceInfoController;
